<template>
	<view class="body">
		<view class="tops">
			<view class="shop">
				<image :src="shop_info.category_image" mode="aspectFill" class="Boutique"></image>
				<view class="title">
					{{shop_info.shop_name}}
				</view>
				<view class="right" @click="toggle">
					<view class="size">
						切换
					</view>
					<image :src="$IMG_URL('/static/home/indicate.png')" mode="aspectFill" class="icon"></image>
				</view>
			</view>
			<headerTwo ref="header" :isLoading="isLoading" @changeIndex="changeHeaderIndex" @dateConfirm="dateConfirm" @refresh="$u.debounce(refresh,500)">
			</headerTwo>
			<view class="sound_box">
				<view class="search">
					<u-search placeholder="会员" :show-action="false" shape="square" v-model="query.search" @change="$u.debounce(getSearch('search'),500)"></u-search>
				</view>
				<view class="search">
					<u-search placeholder="教练" :show-action="false" shape="square" v-model="query.coach_name" @change="$u.debounce(getSearch('coach_name'),500)"></u-search>
				</view>
				<view class="search">
					<u-search placeholder="课程" :show-action="false" shape="square" v-model="query.course_name" @change="$u.debounce(getSearch('course_name'),500)"></u-search>
				</view>
			</view>
		<!-- 	<view class="tabs">
				<view class="Item" v-for="(item,index) in tabslist" :key="index" @click.stop="changeIndex(index)">
					<text class="size" :style="{color:activeIndex == index ?'#73F0EA':'#666666'}">{{item}}</text>
					<view class="bar" :style="{background:activeIndex == index ?'#73F0EA':'#ffffff'}">
			
					</view>
				</view>
			</view> -->
		</view>
		<scroll-view scroll-y="true" class="scroll-view" @scrolltolower="scrolltolower">
			<view class="comlum_Y" v-if="list.length">
				<view v-for="(item,index) in list" :key="index" class="Item">
					<view class="headers">
						<view class="size">
							上课时间：{{item.class_time}}
						</view>
					</view>
					<view class="center">
						<image :src="item.image" mode="aspectFill" class="img"></image>
						<view class="right">
							<view class="title">
								<view class="left_t">
									{{item.title}}
								</view>
							</view>
							<view class="sound">
								<view class="sound_left">
									<text class="size1">第</text>
									<text class="size2">{{item.that}}</text>
									<text class="size1">节丨共{{item.classes}}节</text>
								</view>
								<view class="size1">
									单价￥{{item.cost}}
								</view>
							</view>
						</view>
					</view>
					<view class="bottom">
						<view class="coach_box mb">
							<view class="img_box">
								<image :src="item.coach_avatar" mode="aspectFill" class="imgs"></image>
								<view class="tag2">
									主教
								</view>
							</view>
							<view class="coach_right">
								<view class="name">
									{{item.coach_username}}
								</view>
								<view class="phone_box">
									<image :src="$IMG_URL('/static/test/phone.png')" mode="aspectFill" class="phone_logo"></image>
									<view class="phone_numnber">
										{{item.coach_mobile}}
									</view>
								</view>
							</view>
							<view class="btn all_mr" @click.stop="$COPY(item.mobile)">
								复制
							</view>
							<view class="btn" @click.stop="opentelephoneShow(item.coach_mobile)">
								拨打
							</view>
						</view>
						<view class="coach_box">
							<view class="img_box">
								<image :src="item.avatar" mode="aspectFill" class="imgs"></image>
								<view class="tag">
									学员
								</view>
							</view>
							<view class="coach_right">
								<view class="name">
									{{item.username}}
								</view>
								<view class="phone_box">
									<image :src="$IMG_URL('/static/test/phone.png')" mode="aspectFill" class="phone_logo"></image>
									<view class="phone_numnber">
										{{item.mobile}}
									</view>
								</view>
							</view>
							<view class="btn all_mr" @click.stop="$COPY(item.mobile)">
								复制
							</view>
							<view class="btn" @click.stop="opentelephoneShow(item.mobile)">
								拨打
							</view>
						</view>
					</view>
				</view>
				<u-loadmore :status="status" />
			</view>
			<empty v-else :content="'上课记录'"></empty>
		</scroll-view>
		<telephone :telephoneShow="telephoneShow" :telephone="mobileNumber" @cancel="callCancel" @sure="callSure">
		</telephone>
		<FieldPopupVue :popupShow="popupShow" :FieldList="Field" @sure="sure" @changeActiveIndex="changeActiveIndex"
			:activeIndex="FieldIndex"></FieldPopupVue>
	</view>
</template>

<script>
	import {
		atShop,
		storeCourseClassList
	} from '@/api/manager.js'
	import FieldPopupVue from '../../pages/user/components/Field-popup.vue'
	import headerTwo from '../coach/components/header2.vue'
	import telephone from '@/components/telephone.vue'
	import empty from '@/components/empty.vue'
	export default {
		components: {
			headerTwo,
			telephone,
			empty,
			FieldPopupVue
		},
		data() {
			return {
				isLoading: false,
				status: 'loadmore',
				mobileNumber:'',
				FieldIndex: -1,
				shopName: '',
				popupShow: false,
				shop_info: {},
				activeIndex: 0,
				tabslist: [
					'全部',
					'进行中',
					'已完成'
				],
				// 电话弹窗
				telephoneShow: false,
				telephoneNumber: '',
				list:[],
				query: {
					shop_id: '',
					search:'',
					coach_name:'',
					date_form:'day',
					date:'',
					page:1
				},
			}
		},
		onLoad() {
			this.getatShop()
			this.storeCourseClassList()
		},
		methods: {
			opentelephoneShow(item){
				this.telephoneShow = true
				this.mobileNumber = item
			},
			refresh() {
				// 显示加载动画
				uni.showLoading({
					title: '加载中...',
					mask: true // 是否显示透明蒙层，防止触摸穿透
				});
			
				// 重置查询参数和列表数据
				this.query.page = 1;
				this.list = [];
			
				// 模拟请求数据（在实际应用中，你应该使用真实的网络请求）
				setTimeout(() => {
					// 请求完成后隐藏加载动画
					uni.hideLoading();
			
					this.storeCourseClassList()
				}, 1500); // 模拟请求延迟1.5秒
			},
			scrolltolower() {
				this.query.page++
				this.storeCourseClassList()
			},
			getSearch() {
				this.list = []
				this.query.page = 1
				this.storeCourseClassList()
			
			},
			changeHeaderIndex(e) {
				this.query.date_form = e == 0 ? 'day' : e == 1 ? 'month' : 'year'
				this.query.date = this.$refs.header.day
				console.log('form', this.query.form);
				this.query.page = 1
				this.list = []
				this.storeCourseClassList()
			},
			dateConfirm(e, data) {
				console.log('e321', data);
				this.query.date = data
				this.query.page = 1
				this.list = []
				this.storeCourseClassList()
			},
			storeCourseClassList() {
				if (this.isLoading) {
					console.log('请求未完成，请稍后');
					return;
				}
				this.isLoading = true;
				uni.showLoading()
				storeCourseClassList(this.query).then(({
					data: res
				}) => {
					console.log('res', res);
					if (res.code == 1) {
						const list = []
						this.status = 'loading'
						if (this.query.page > res.data.all_page) {
							console.log('nomore');
							this.status = 'nomore'
							return false
						} else {
							console.log('more');
							this.status = 'more'
							this.list = this.list.concat(res.data.list)
						}
			
						console.log('list', this.list);
					}
				}).finally(()=>{
					uni.hideLoading();
					this.isLoading = false
				})
			},
			sure() {
				this.popupShow = false
			},
			changeActiveIndex(item, index) {
				this.FieldIndex = index
				this.getatShop({
					shop_id: item.shop_id
				})
				this.query.shop_id = item.shop_id
				this.list = []
				this.query.page = 1
				this.storeCourseClassList()
			},
			toggle() {
				console.log(11);
				this.popupShow = true
			},
			getatShop(e) {
				atShop(e).then(({
					data: res
				}) => {
					console.log('res', res);
					if (res.code == 1) {
						this.shop_info = res.data
					}
				})
			},
			callSure() {
				let that = this
				uni.makePhoneCall({
					phoneNumber: that.mobileNumber, // 必填，需要拨打的电话号码
					success: function() {
						console.log('拨打电话成功！');
						// 这里可以添加拨打成功后的逻辑，比如提示用户
					},
					fail: function(err) {
						console.log('拨打电话失败：', err);
						// 这里可以添加拨打失败后的逻辑，比如提示用户错误原因
					}
				});
				this.telephoneShow = false
			},
			callCancel() {
				this.telephoneShow = false
			},
			changeIndex(index){
				this.activeIndex = index
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #e9e9e9;

	}

	.body {
		display: flex;
		flex-direction: column;
		align-items: center;
	}
	
	.shop {
		width: 100%;
		display: flex;
		flex-direction: row;
		align-items: center;
		margin-bottom: 22rpx;
		padding: 0 23rpx;
	
		.Boutique {
			width: 114rpx;
			height: 36rpx;
			margin-right: 12rpx;
		}
	
		.title {
			flex: 1;
			font-size: 28rpx;
			font-family: PingFang SC, PingFang SC-Bold;
			font-weight: 700;
			text-align: left;
			color: #333333;
		}
	
		.right {
			display: flex;
			flex-direction: row;
			align-items: center;
	
			.size {
				font-size: 28rpx;
				font-family: PingFang SC, PingFang SC-Regular;
				font-weight: 400;
				color: #666666;
				margin-right: 8rpx;
			}
	
			.icon {
				width: 10rpx;
				height: 16rpx;
			}
		}
	}
	.tops {
		width: 750rpx;
		padding: 24rpx 0 0;
		background: #ffffff;
		display: flex;
		flex-direction: column;
		align-items: center;

		.sound_box {
			width: 100%;
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: space-around;
			padding: 24rpx 19rpx;
		}

		.search {
			width: 222rpx;
		}
		.tabs {
			width: 750rpx;
			height: 88rpx;
			background: #ffffff;
			box-shadow: 0rpx 8rpx 28rpx 0rpx rgba(199, 205, 179, 0.15);
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: space-around;
			padding-top: 25rpx;
		
			.Item {
				display: flex;
				flex-direction: column;
				align-items: center;
		
				.size {
					font-size: 32rpx;
					font-family: PingFang SC, PingFang SC-Regular;
					font-weight: 400;
					text-align: center;
					color: #666666;
					margin-bottom: 12rpx;
				}
		
				.bar {
					width: 44rpx;
					height: 8rpx;
					border: 2rpx solid rgba(0, 0, 0, 0.00);
					border-radius: 2rpx;
				}
			}
		}

	}

	.scroll-view {
		width: 100%;
		height: 80vh;
		.comlum_Y{
			display: flex;
			flex-direction: column;
			align-items: center;
			padding-top: 24rpx;
			.Item{
				width: 702rpx;
				height: 528rpx;
				background: #ffffff;
				border-radius: 16rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				margin-bottom: 20rpx;
				padding: 24rpx;
				.headers{
					width: 100%;
					padding-bottom: 22rpx;
					border-bottom: 1rpx solid #e9e9e9;
					display: flex;
					flex-direction: row;
					align-items: center;
					.size{
						font-size: 28rpx;
						font-family: PingFang SC, PingFang SC-Bold;
						font-weight: 700;
						text-align: left;
						color: #333333;
						flex: 1;
					}
					.color1{
						color: #73F0EA;
					}
					.color2{
						color: #999999;
					}
				}
				.center{
					padding: 26rpx 0 22rpx;
					width: 100%;
					display: flex;
					flex-direction: row;
					border-bottom: 1rpx solid #e9e9e9;
					.img{
						width: 160rpx;
						height: 120rpx;
						background: rgba(0,0,0,0.00);
						border-radius: 16rpx;
						margin-right: 20rpx;
					}
					.right{
						display: flex;
						flex-direction: column;
						flex: 1;
						.title{
							display: flex;
							flex-direction: row;
							align-items: center;
							margin-bottom: 8rpx;
							.left_t{
								flex: 1;
								font-size: 32rpx;
								font-family: PingFang SC, PingFang SC-Bold;
								font-weight: 700;
								text-align: left;
								color: #333333;
							}
							.right_t{
								display: flex;
								flex-direction: row;
								align-items: baseline;
								color: #f37364;
								font-weight: 700;
								.size1{
									font-size: 24rpx;
								}
								.size2{
									font-size: 32rpx;
								}
							}
						}
						.sound{
							display: flex;
							flex-direction: row;
							align-items: center;
							width: 100%;
							.size1{
								font-size: 24rpx;
								font-family: PingFang SC, PingFang SC-Medium;
								font-weight: 500;
								text-align: left;
								color: #999999;
							}
							.size2{
								font-size: 24rpx;
								font-family: PingFang SC, PingFang SC-Medium;
								font-weight: 500;
								text-align: left;
								color: #73F0EA;
							}
							.sound_left{
								flex: 1;
							}
						}
					}
				}
				.bottom{
					padding-top: 28rpx;
					width: 100%;
					display: flex;
					flex-direction: column;
					.mb{
						margin-bottom: 32rpx;
					}
					.shop_box{
						display: flex;
						flex-direction: row;
						align-items: center;
						margin-bottom: 22rpx;
						.logos{
							width: 114rpx;
							height: 36rpx;
							margin-right: 12rpx;
						}
						.shop_size{
							font-size: 28rpx;
							font-family: PingFang SC, PingFang SC-Bold;
							font-weight: 700;
							text-align: right;
							color: #333333;
						}
					}
					.coach_box{
						display: flex;
						flex-direction: row;
						align-items: center;
						.img_box{
							width: 92rpx;
							height: 92rpx;
							position: relative;
							margin-right: 20rpx;
							.imgs{
								width: 92rpx;
								height: 92rpx;
								background: rgba(0,0,0,0.00);
								border-radius: 50%;
							}
							.tag2{
								position: absolute;
								left: 50%;
								bottom: -10%;
								transform: translate(-50%, 0);
								width: 60rpx;
								height: 36rpx;
								background: #73F0EA;
								border-radius: 8rpx;
								font-size: 22rpx;
								font-family: PingFang SC, PingFang SC-Medium;
								font-weight: 500;
								text-align: left;
								color: #ffffff;
								display: flex;
								align-items: center;
								justify-content: center;
							}
							.tag{
								position: absolute;
								left: 50%;
								bottom: -10%;
								transform: translate(-50%, 0);
								width: 60rpx;
								height: 36rpx;
								background: #fdc62b;
								border-radius: 8rpx;
								font-size: 22rpx;
								font-family: PingFang SC, PingFang SC-Medium;
								font-weight: 500;
								text-align: left;
								color: #ffffff;
								display: flex;
								align-items: center;
								justify-content: center;
							}
						}
						.coach_right{
							display: flex;
							flex-direction: column;
							flex: 1;
							.name{
								font-size: 28rpx;
								font-family: PingFang SC, PingFang SC-Bold;
								font-weight: 700;
								text-align: left;
								color: #333333;
								margin-bottom: 12rpx;
							}
							.phone_box{
								display: flex;
								flex-direction: row;
								align-items: center;
								flex: 1;
								.phone_logo{
									width: 20rpx;
									height: 30rpx;
									margin-right: 7rpx;
								}
								.phone_numnber{
									font-size: 28rpx;
									font-family: PingFang SC, PingFang SC-Medium;
									font-weight: 500;
									text-align: left;
									color: #666666;
								}
							}
							
						}
						.btn{
							transform: rotateZ(360deg);
							width: 112rpx;
							height: 64rpx;
							border: 1rpx solid #73F0EA;
							border-radius: 16rpx;
							font-size: 28rpx;
							font-family: PingFang SC, PingFang SC-Bold;
							font-weight: 700;
							text-align: center;
							color: #73F0EA;
							display: flex;
							align-items: center;
							justify-content: center;
						}
					}
				}
			}
		}
	}
</style>